package bean;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

@EqualsAndHashCode(callSuper = true)
@Data
@ToString(callSuper = true)
public class CheckAccount extends Account {
    private double overdraft;

    public CheckAccount() {
    }

    public CheckAccount(double balance, double annualInterestRate, double overdraft) {
        super(balance, annualInterestRate);
        this.overdraft = overdraft;
    }

    @Override
    public void withdraw(double money) {
        if (super.getBalance() >= money)
            super.withdraw(money);
        else {
            if (this.overdraft > money - super.getBalance()) {
                this.overdraft = this.overdraft - (money - super.getBalance());
                setBalance(0);
            } else
                System.out.println("可透支额度不足！当前仅剩：" + this.overdraft);
        }
    }
}
